package com.miracle.controller;

import com.miracle.common.response.Result;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jie.xi
 * @date 2022年05月18日 14:51
 */

@RestController
@RequestMapping("/tb-user")
public class TestController {

    @RequestMapping("/test")
    public Result test(){
        return Result.success();
    }

    @RequestMapping("/test2")
    public Result test2(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        AbstractAuthenticationToken test = (AbstractAuthenticationToken) authentication;
        Object details = test.getDetails();
        System.out.println(details.toString());

        UsernamePasswordAuthenticationToken test2 = (UsernamePasswordAuthenticationToken) authentication;
        Object principal = test2.getPrincipal();
        System.out.println(principal.toString());

        Object credentials = test2.getCredentials();
        System.out.println(credentials.toString());

        return Result.success();
    }
}
